package com.macro.mall.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsJobParam;
import com.macro.mall.model.BmsJob;
import com.macro.mall.service.BmsJobService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 岗位
 * Created 2024/8/13.
 *
 */
@Controller
@Api(tags = "BmsJob")
@Tag(name = "BmsJob", description = "岗位")
@RequestMapping("/bmsJob")
public class BmsJobController {

    @Autowired
    private BmsJobService bmsJobService;
    
    @ApiOperation("添加岗位")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsJobParam bmsJobParam) {
        int count = bmsJobService.create(bmsJobParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    
    @ApiOperation("修改岗位")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsJobParam bmsJobParam) {
        int count = bmsJobService.update(bmsJobParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    
    @ApiOperation("分页岗位")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsJob>> getList(@RequestBody BmsJobParam bmsJobParam) {
        List<BmsJob> bmsJobList = bmsJobService.getList(bmsJobParam);
        return CommonResult.success(CommonPage.restPage(bmsJobList));
    }
    
    @ApiOperation("根据id获取岗位")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsJob> getItem(@PathVariable Long id) {
    	BmsJob bmsJob = bmsJobService.getItem(id);
        return CommonResult.success(bmsJob);
    }
    
    @ApiOperation("删除岗位")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestParam("ids") List<Long> ids) {
        int count = bmsJobService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    
    @ApiOperation("获取岗位列表")
    @RequestMapping(value = "/jobList", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<List<BmsJob>> getJobList() {
        List<BmsJob> bmsJobList = bmsJobService.getJobList();
        System.out.println(bmsJobList);
        return CommonResult.success(bmsJobList);
    }
    

}
